/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.designtime.generator.metadatacompile;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.bef.bizentity.GspBusinessEntity;
import com.inspur.edp.bef.bizentity.operation.BizMgrAction;
import com.inspur.edp.bef.bizentity.operation.BizOperation;
import com.inspur.edp.bef.bizentity.operation.collection.BizMgrActionCollection;
import com.inspur.edp.bff.designtime.generator.VmGenerator;
import com.inspur.edp.bff.designtime.generator.VmGeneratorContext;
import com.inspur.edp.caf.generator.module.ModuleGenerator;
import com.inspur.edp.cef.designtime.api.IGspCommonField;
import com.inspur.edp.cef.designtime.api.collection.GspAssociationCollection;
import com.inspur.edp.cef.designtime.api.collection.GspEnumValueCollection;
import com.inspur.edp.cef.designtime.api.collection.GspFieldCollection;
import com.inspur.edp.cef.designtime.api.element.GspAssociation;
import com.inspur.edp.cef.designtime.api.element.GspElementObjectType;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import com.inspur.edp.das.commonmodel.collection.GspElementCollection;
import com.inspur.edp.formserver.viewmodel.GspViewModel;
import com.inspur.edp.formserver.viewmodel.GspViewModelElement;
import com.inspur.edp.formserver.viewmodel.GspViewObject;
import com.inspur.edp.formserver.viewmodel.action.ViewModelAction;
import com.inspur.edp.formserver.viewmodel.action.ViewModelActionType;
import com.inspur.edp.formserver.viewmodel.collection.VMActionCollection;
import com.inspur.edp.formserver.viewmodel.collection.VMElementCollection;
import com.inspur.edp.jittojava.context.JitContext;
import com.inspur.edp.jittojava.spi.JitAction;
import com.inspur.edp.lcm.metadata.api.entity.GspMetadata;
import io.iec.edp.caf.commons.exception.CAFRuntimeException;
import io.iec.edp.caf.commons.exception.ExceptionLevel;

import java.util.ArrayList;

public class VoJitAction implements JitAction {

  @Override
  public final void generateApi(JitContext context) {
    VmGenerator beGen = new VmGenerator(context.getMetadata().getRelativePath(), context.getMetadata(), true,
            context.getApiModuleGenerator(), context);
    VmCoincidenceCheck coincidenceCheck = new VmCoincidenceCheck(context);
    coincidenceCheck.checkVmAndBeCoincidence();

    context.getApiModuleGenerator().addExtendChildGenrator(beGen);
    if (context.getExtendProperty() == null) {
      context.setExtendProperty( new java.util.HashMap<String, Object>());
    }
    context.getExtendProperty().put(((GspViewModel)context.getMetadata().getContent()).getID()+"GenCtx", beGen);
  }

  @Override
  public final void generateCore(JitContext context) {
    VmGenerator begen =
            (VmGenerator)
                    context.getExtendProperty().get(((GspViewModel)context.getMetadata().getContent()).getID()+"GenCtx");
    VmGenerator voCoreGenerator = new VmGenerator(context.getMetadata().getRelativePath(), context.getMetadata(),
            begen.getContext(), null, context.getCoreModuleGenerator(), context);
    context.getCoreModuleGenerator().addExtendChildGenrator(voCoreGenerator);
  }
}
